<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>NexHome Admin</title>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />

    <!-- libraries -->
   <link href="css/lib/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" />
    <link href="css/lib/font-awesome.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/layout.css" />
    <link rel="stylesheet" type="text/css" href="css/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/icons.css" />
	
   
   <!-- this page specific styles -->
   <link rel="stylesheet" href="css/compiled/new-user.css" type="text/css" media="screen" />  
   <!-- open sans font -->
    <link href='css/OpenSans.css' rel='stylesheet' type='text/css' />

    <!-- lato font -->
    <link href='css/Lato.css' rel='stylesheet' type='text/css' />
	
<!--[if lt IE 9]>
      <script src="js/html5.js"></script>
    <![endif]--> 
	 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="js/jquery-1.10.2.min.js"></script>
	<script type="text/javascript" src="js/ajaxfileupload.js"></script>
	<script type="text/javascript" src="js/jquery.fileDownload.min.js"></script>
  </head>

  
  <script>
function request()
{ 
	var url = location.href;
	var paraString;
	if(url.indexOf("devid") != -1){ 
 	paraString = url.substring(url.indexOf("=")+1,url.length);	 
	}
	else{
	paraString = "NO";
	}
	return paraString;  	
	
}
$(document).ready(function() {
  	currusername = request();	
	if(currusername != 'NO'){
		$('#Routerid').val(currusername);
		$('#Routeriddown').val(currusername);
	}
	$('#type').val("dev");
	$("#type option[value='dev']").attr("selected","selected");
  	$("#buttonUpload").click(function(){
			if($('#Routerid').val() == '' || $('#Routerid').val().length == 0){
				alert('请输入路由器NID');
				return;
			}
		 if ($("#fileToUpload").val().length > 0) {
					  ajaxFileUpload();
		  }
		 else {
					alert("请选择配置文件");
		  }     
    });
	$("#buttonDownload").click(function(){
		var username = $('#Routeriddown').val();
		var type = $('#type').val();
		if($('#Routeriddown').val() == '' || $('#Routeriddown').val().length == 0){
				alert('请输入路由器NID');
				return;
		}
		var fname = username + "-" + type +".xml";		
				
		var path = "../mgrShConf/"+fname;				
		$.fileDownload(path,{contentType: "application/xml"})
		.done(function () {
			alert("配置文件下载成功"); 
		 })
		.fail(function () { 
			alert("配置文件下载失败"); 
		});
									
    });
});
  function ajaxFileUpload(){
  	var username = $('#Routerid').val();
	  $.ajaxFileUpload({
			url:'../mgrShConf',
			secureuri :false,
			fileElementId :'fileToUpload',
			dataType : 'json',
			data:{nid: username},
			success : function (data){
			   if(data.resultCode != '10000'){
					
						alert(data.resultMsg);
					}else{
						alert(data.resultMsg);
					}
				
			},
			error: function(){
				alert("上传配置文件链接超时");
			}
		})
	 return false;
}
  </script>
  <body> 
  <!--<![endif]-->
    
   
 	<!-- main container -->
    <div class="content">       
        <div class="container-fluid">
         <div id="pad-wrapper" class="new-user">
   
   			 <div class="row-fluid header">
                    <h3>配置文件上传&nbsp;&nbsp;&nbsp;</h3>
                    			                    
            </div>
   			<div class="row-fluid form-wrapper">
                    <!-- left column -->
                    <div class="span9 with-sidebar">
                        <div class="container">
							<form>
							<div class="span12 field-box">
                                    <label>输入路由器NID:</label>
                                    <input class="span9" id="Routerid" name="Routerid" type="text"  />
                            </div>
							<div class="span12 field-box">
							<label>配置文件:</label>
							<input type="file"   name="fileToUpload" id="fileToUpload"></input>
							</div>
							<div class="span10">
							<div class="alert alert-info hidden-tablet">
                            <i  style="top:0;" class="icon-lightbulb pull-left"></i>
                            选择请选择符合格式的配置文件：<br>如果上传app的配置文件，请将配置文件名称改为：nid-app.xml;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果上传dev的配置文件，请将配置文件名称改为：nid-dev.xml;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;例如nid为67697,那么app配置文件名就是67697-app.xml,dev配置文件名就是67697-dev.xml.
                        	</div>
							</div>
														
							
							
							<div class="span11 field-box actions">
                                    <input type="button" class="btn-glow primary" id="buttonUpload" value="上传" />
                                    <span>OR</span>
									
                                    <input type="reset" value="取消" class="reset" />
                                </div>
							
							</form>
				 		</div>
        			</div>
				</div>
       
	   <div class="row-fluid header">
                    <h3>配置文件下载&nbsp;&nbsp;&nbsp;</h3>
                    			                    
            </div>
   			<div class="row-fluid form-wrapper">
                    <!-- left column -->
                    <div class="span9 with-sidebar">
                        <div class="container">
							<form>
							<div class="span12 field-box">
                                    <label>输入路由器NID:</label>
                                    <input class="span9" id="Routeriddown" name="Routeriddown" type="text"  />
                            </div>
							<div class="span12 field-box">
                                    <label>下载的文件类型:</label>
                                    <select name="type" id="type">
									<option value="app">app</option>
									<option value="dev">dev</option>
									</select>
                            </div>
							<div class="span10">
							<div class="alert alert-info hidden-tablet">
                            <i  style="top:0;" class="icon-lightbulb pull-left"></i>
                            请在“下载的文件类型”中选择需要的配置文件
                        	</div>
							</div>
							
							<div class="span11 field-box actions">                                  
									<input type="button" class="btn-glow primary" id="buttonDownload" value="下载" />
									<span>OR</span>
                                    <input type="reset" value="取消" class="reset" />
                                </div>
							
							</form>
				 		</div>
        			</div>
				</div>
        
</div>
</div>
</div>

</body>
</html>